package OSMS.action.Boss;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import OSMS.dao.GoodsDao;
import OSMS.entity.Goods;

/**
 * ��תҳ��
 */
public class ToGoodsUpdateServlet extends HttpServlet{

	private GoodsDao gdao = new GoodsDao();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			HttpSession session = request.getSession();
			response.setCharacterEncoding("utf-8");
			request.setCharacterEncoding("utf-8");
			//接收bid gid
			String id1 = request.getParameter("gid");
			String id2 = request.getParameter("bid");
			int gid  = 0;
			int bid = 0;
			if(id1 != null) {
				gid = Integer.parseInt(id1);
			}
			if(id2 != null) {
				bid = Integer.parseInt(id2);
			}
			
			request.getSession().setAttribute("gid", gid);
			request.getSession().setAttribute("bid", bid);
			
			
			
			//根据gid查询商品信息
			Goods good = gdao.getGoodsById(gid);
			
			session.setAttribute("good", good);
			
			//请求转发到updategoods.jsp

			request.setCharacterEncoding("utf-8");
			request.getRequestDispatcher("updategoods.jsp").forward(request, response);
		} catch(Exception ex) {
			ex.printStackTrace();
		}
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
	
	

}
